package coder.user.controller;

import coder.common.Result;
import coder.user.entity.Comment;
import coder.user.service.ICommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("comment")
public class CommentController {

    @Autowired
    private ICommentService commentService;

    @PostMapping("add")
    public Result<String> saveComment(@ModelAttribute Comment comment) {
        commentService.saveComment(comment);
        return Result.success();
    }

    @GetMapping("query")
    public Result<List<Comment>> queryComment() {
        return Result.success(commentService.queryComment());
    }

    @PostMapping("update")
    public Result<String> updateComment(@ModelAttribute Comment comment) {
        commentService.updateComment(comment);
        return Result.success();
    }

    @PostMapping("del")
    public Result<String> delComment(@RequestParam String id) {
        Comment comment = new Comment();
        comment.setId(id);
        comment.setIsDelete(1);
        commentService.updateComment(comment);
        return Result.success();
    }
}
